<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
  </ul>
  <script>

    /*
      let 和 var的区别
        1、let不能重复声明同名变量
        2、不存在变量提升（暂时性死区）
        3、存在块级作用域

      const
        1、定义的是常量，不能后续改值 ---- 不能改地址
        2、必须定义即赋值
     */
    // var a = 1
    // var a = 2
    // console.log(a);
    // let a = 1
    // let a = 2
    // console.log(a);


    // console.log(a); //undefined
    // var a = 1

    // console.log(a);//Cannot access 'a' before initialization
    // let a = 1


    var lis = document.getElementsByTagName('li');
    for (let i = 0; i < lis.length; i++) {
      ////1
      lis[i].onclick = function () {
        ///2
        console.log(i);
      }
    }

    // var a = 1
    // a =2
    // console.log(a);
    // let a = 1
    // a = 2
    // console.log(a);

    // const a = 1
    // a = 2//Assignment to constant variable.
    // console.log(a);

    // let a
    // console.log(a);//undefined
    // a = 1;
    // const a//报错
    // console.log(a);
    // a = 1;

    const obj1 = {
      name: 'lisi'
    };
    // obj1.name = 'wangwu'
    obj1 = { name: 'wangwu' };
    console.log(obj1);
  </script>
</body>

</html>